
/**
 * Module dependencies.
 */

var express = require('express')
  , routes = require('./routes')
  , http = require('http')
  , path = require('path')
  , setting = require('./appsettings');

var app = express();

app.configure(function(){
  app.set('port', process.env.PORT || 30000);
  app.set('views', __dirname + '/views');
  app.set('view engine', 'jade');
  app.use(express.favicon());
  app.use(express.logger('dev'));
  app.use(express.bodyParser());
  app.use(express.methodOverride());
  app.use(app.router);
  app.use(express.static(path.join(__dirname, 'public')));

  //这个cookieParser是express提供的一个分析Cookie信息，并将信息保存在req.cookie中的中间件
  //如想通过req.cookie获得cookie的值，一定要加这句
  app.use(express.cookieParser());

  //靠这个中间件让我们可以用req.session.key获取对应的value
 //  app.use(session({
 //     cookie: { maxAge: 600000 },
 //     secret: Settings.COOKIE_SECRET,
 //     store: new MongoStore({  
 //         username: Settings.USERNAME,
 //         password: Settings.PASSWORD,
 //         url: Settings.URL,
 //         db: db})
 // }))
  // http://www.cnblogs.com/Leo_wl/p/3920907.html
  
});

app.configure('development', function(){
  app.use(express.errorHandler());
});

routes.view(app);

http.createServer(app).listen(app.get('port'), function(){
  console.log("Express server listening on port " + app.get('port'));
});
